package com.jane.adapter.hostheadlinesadapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.jane.bean.HostHeadLinesBean;
import com.jane.gzzb.HostHeadLinesActivity;
import com.jane.gzzb.R;
import com.jane.utils.Utils;
import com.jane.view.RoundImageView;
import java.util.ArrayList;

/**
 * Created by Grace on 2016/11/14.
 */

public class HostHeadAdapter extends BaseAdapter {
    private static final String TAG=HostHeadAdapter.class.getSimpleName();
    private Context mContext;
    private ArrayList<HostHeadLinesBean.DataListBean> data;

    public HostHeadAdapter(Context mContext, ArrayList<HostHeadLinesBean.DataListBean> data) {
        this.mContext = mContext;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data==null?0:data.size();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView=View.inflate(mContext,R.layout.hostfragment_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        //设置图片
        Utils.loadImage(holder.ivHead,data.get(position).getUser_info().getIcon());
        ArrayList<HostHeadLinesBean.DataListBean.PicsBean> data1= (ArrayList<HostHeadLinesBean.DataListBean.PicsBean>) data.get(position).getPics();
           if(data1.get(0).getSmall_url()!=null){
               Utils.loadImage(holder.ivRight,data1.get(0).getSmall_url());
           }

        //设置文本
        holder.tvTitle.setText(data.get(position).getUser_info().getUser_name());
        holder.tvDetailFirst.setText(data.get(position).getName());
        holder.tvDetailSecond.setText(data.get(position).getExcerpt());
        holder.tvTags.setText(data.get(position).getTags());
        holder.tvCount.setText(data.get(position).getSee_count()+"");
        return convertView;
    }

     static class ViewHolder{
        private RoundImageView ivHead;
        private ImageView ivRight;
        private TextView tvTitle,tvDetailFirst,tvDetailSecond,tvTags,tvCount;
        public ViewHolder(View itemView){
            ivHead= (RoundImageView) itemView.findViewById(R.id.host_item_iv1);
            ivRight= (ImageView) itemView.findViewById(R.id.host_item_iv2);

            tvTitle= (TextView) itemView.findViewById(R.id.host_item_title);
            tvDetailFirst= (TextView) itemView.findViewById(R.id.host_item_detail_tv1);
            tvDetailSecond= (TextView) itemView.findViewById(R.id.host_item_detail_tv2);
            tvTags= (TextView) itemView.findViewById(R.id.host_item_tv_tags);
            tvCount= (TextView) itemView.findViewById(R.id.host_item_tv_count);
        }
    }
}
